<template>
  <div>
    <h1>App组件</h1>
    <keep-alive>
      <component :is="comName"></component>
    </keep-alive>
    <button @click="changeCom">切换组件</button>
  </div>
</template>

<script>
import component from "./component.vue";
import component1 from "./component1.vue";
export default {
  components: { component, component1 },
  name: "myApp",
  data() {
    return {
      comName: "component",
    };
  },
  methods: {
    changeCom() {
      if (this.comName === "component") return (this.comName = "component1");
      this.comName = "component";
    },
  },
};
</script>

<style>
</style>